home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWMenu / Include / FWMnuBar.h < prev    next >
Encoding:
Text File  |  1996-04-25  |  8.4 KB  |  276 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWMnuBar.h
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWMNUBAR_H
  11. #define FWMNUBAR_H
  12.  
  13. #ifndef FWPULLDM_H
  14. #include "FWPullDM.h"
  15. #endif
  16.  
  17. #ifndef FWCOMMON_H
  18. #include "FWCommon.h"
  19. #endif
  20.  
  21. #ifndef FWDEBUG_H
  22. #include "FWDebug.h"
  23. #endif
  24.  
  25. #ifndef FWTCOLL_H
  26. #include "FWTColl.h"
  27. #endif
  28.  
  29. // ----- OpenDoc Includes -----
  30.  
  31. #ifndef SOM_ODMenuBar_xh
  32. #include <MenuBar.xh>
  33. #endif
  34.  
  35. // ----- Platform Includes -----
  36.  
  37. #if defined(FW_BUILD_WIN) && !defined(_INC_WINDOWS)
  38. #include <windows.h>
  39. #endif
  40.  
  41. //========================================================================================
  42. //    Forward class definitions
  43. //========================================================================================
  44.  
  45. class ODPart;
  46. class FW_CString;
  47. class FW_CMenuItem;
  48.  
  49. //========================================================================================
  50. //    class FW_CMenuBar
  51. //========================================================================================
  52.  
  53. class FW_CMenuBar
  54. {
  55. //----------------------------------------------------------------------------------------
  56. //    Constructors/Destructors
  57. //
  58. public:
  59.     FW_CMenuBar(Environment* ev, ODPart* thePart, FW_Instance partInstance);
  60.     virtual ~FW_CMenuBar();
  61.     
  62. //----------------------------------------------------------------------------------------
  63. //    New API
  64. //
  65. public:
  66.     // ----- Adding -----
  67.     void                InitializeFromResource(Environment* ev, FW_ResourceId menuBarResourceID);
  68.     void                InitializeFromStream(Environment* ev, FW_CReadableStream& stream);
  69.     
  70.     void                 AdoptMenuFirst(Environment* ev, 
  71.                             FW_CPullDownMenu* menu);
  72.     void                 AdoptMenuLast(Environment* ev, 
  73.                             FW_CPullDownMenu* menu);
  74.                             
  75.     void                 AdoptMenuBefore(Environment* ev, 
  76.                             FW_CPullDownMenu* menu, 
  77.                             FW_CPullDownMenu* beforeMenu);    // if beforeMenu == NULL -> AdoptMenuFirst
  78.     void                 AdoptMenuAfter(Environment* ev, 
  79.                             FW_CPullDownMenu* menu, 
  80.                             FW_CPullDownMenu* afterMenu);    // if afterMenu == NULL -> AdoptMenuLast
  81.  
  82.     // ----- Removing/Detaching -----
  83.     void                 DetachMenu(Environment* ev, 
  84.                             FW_CPullDownMenu* menuToDetach);    
  85.     void                 DeleteMenu(Environment* ev, 
  86.                             FW_CPullDownMenu* menuToDelete);    // DetachMenu + delete of the menu
  87.     void                 DeleteAll(Environment* ev);
  88.  
  89.     void                RemoveItem(Environment* ev, ODCommandID commandID);
  90.     
  91.     // ----- Item access -----
  92.     void                 SetItemString(Environment* ev,
  93.                             ODCommandID commandID, 
  94.                             const FW_CString& itemString);
  95.     void                 GetItemString(Environment* ev, 
  96.                             ODCommandID commandID, 
  97.                             FW_CString& itemString) const;
  98.     
  99.     void                 EnableCommand(Environment* ev, 
  100.                             ODCommandID cmdNumber, 
  101.                             FW_Boolean enable);
  102.     void                 CheckCommand(Environment* ev, 
  103.                             ODCommandID cmdNumber, 
  104.                             FW_Boolean check);
  105.     void                 ToggleItem(Environment* ev, 
  106.                             ODCommandID cmdNumber, 
  107.                             FW_Boolean toggleState);
  108.                             
  109.     void                 EnableAndCheckCommand(Environment* ev, 
  110.                             ODCommandID cmdNumber, 
  111.                             FW_Boolean enable,
  112.                             FW_Boolean check);
  113.     void                 EnableAndToggleCommand(Environment* ev, 
  114.                             ODCommandID cmdNumber, 
  115.                             FW_Boolean enable,
  116.                             FW_Boolean toggleState);
  117.  
  118.     FW_MenuKey            GetMenuKey(Environment* ev,
  119.                             ODCommandID cmdNumber) const;
  120.                         
  121.     void                DisableAll(Environment* ev);
  122.     void                EnableAll(Environment* ev);
  123.     
  124.     // ----- Getters/Setters -----    
  125.     FW_CMenuItem*        GetMenuItemFromCommand(Environment* ev, 
  126.                             ODCommandID cmdNumber) const;
  127.                                 
  128.     ODMenuBar*            AcquireODMenuBar(Environment* ev) const;
  129.     ODPart*                GetODPart(Environment* ev) const;
  130.     
  131.  
  132. //----------------------------------------------------------------------------------------
  133. //    Internal API
  134. //
  135. public:
  136.     void                 PrivDisplay(Environment* ev);    
  137.     
  138.     FW_CPullDownMenu*     PrivFindMenuWithID(Environment* ev, 
  139.                             ODMenuID menu) const;
  140.         
  141.     ODMenuID            PrivGetNewMenuID(Environment* ev);
  142.  
  143. #ifdef FW_BUILD_MAC
  144.     void                PrivMacEnableParentItem(Environment* ev, 
  145.                             ODCommandID cmdNumber);
  146.     
  147.     void                PrivMacRegisterCommand(Environment* ev,
  148.                             ODCommandID commandID,
  149.                             ODMenuID menuID,
  150.                             short itemID);
  151.     void                PrivMacUnregisterCommand(Environment* ev,
  152.                             ODCommandID commandID);
  153.     ODCommandID            PrivMacGetCommand(Environment* ev,
  154.                             ODMenuID menuID,
  155.                             short itemID);
  156.     
  157. #endif
  158.  
  159.     void                PrivAddSubMenu(Environment* ev,
  160.                             ODMenuID subMenuID,
  161.                             ODPlatformMenu platformMenu);
  162.     void                PrivRemoveMenu(Environment* ev, 
  163.                                         ODMenuID menuID);
  164.                             
  165. //----------------------------------------------------------------------------------------
  166. //    Platform specific API
  167. //
  168. #ifdef FW_BUILD_MAC
  169. public:
  170.     // ----- Enable/Disable of the whole menuBar -----
  171.     void                MacEnableMenuBar(Environment* ev, 
  172.                             FW_Boolean enable);
  173. #endif
  174.                         
  175. //----------------------------------------------------------------------------------------
  176. //    Data Members
  177. //
  178. private:
  179.     ODMenuBar*                                        fODMenuBar;
  180.     ODPart*                                            fODPart;
  181.     FW_TOrderedCollection<FW_CPullDownMenu>*        fPullDownMenuList;
  182.     ODMenuID                                        fNextMenuID;
  183.     FW_Instance                                        fPartInstance;
  184. };
  185.  
  186. //========================================================================================
  187. //    FW_CMenuBar inlines
  188. //========================================================================================
  189.  
  190. //----------------------------------------------------------------------------------------
  191. //    FW_CMenuBar::PrivDisplay
  192. //----------------------------------------------------------------------------------------
  193. inline void FW_CMenuBar::PrivDisplay(Environment* ev)
  194. {
  195.     fODMenuBar->Display(ev);
  196. }
  197.  
  198. //----------------------------------------------------------------------------------------
  199. //    FW_CMenuBar::GetODPart
  200. //----------------------------------------------------------------------------------------
  201. inline ODPart* FW_CMenuBar::GetODPart(Environment*) const
  202. {
  203.     return fODPart;
  204. }
  205.  
  206. //----------------------------------------------------------------------------------------
  207. //    FW_CMenuBar::PrivGetNewMenuID
  208. //----------------------------------------------------------------------------------------
  209. inline ODMenuID FW_CMenuBar::PrivGetNewMenuID(Environment*)
  210. {
  211.     FW_ASSERT(fNextMenuID < 255);
  212.     return fNextMenuID++;
  213. }
  214.  
  215. #ifdef FW_BUILD_MAC
  216. //----------------------------------------------------------------------------------------
  217. //    FW_CMenuBar::PrivMacRegisterCommand
  218. //----------------------------------------------------------------------------------------
  219. inline void FW_CMenuBar::PrivMacRegisterCommand(Environment* ev,
  220.                                                 ODCommandID commandID,
  221.                                                 ODMenuID menuID,
  222.                                                 short itemID)
  223. {
  224.     fODMenuBar->RegisterCommand(ev, commandID, menuID, itemID);
  225. }
  226. #endif
  227.  
  228. #ifdef FW_BUILD_MAC
  229. //----------------------------------------------------------------------------------------
  230. //    FW_CMenuBar::PrivMacUnregisterCommand
  231. //----------------------------------------------------------------------------------------
  232. inline void FW_CMenuBar::PrivMacUnregisterCommand(Environment* ev,
  233.                                                 ODCommandID commandID)
  234. {
  235.     fODMenuBar->UnregisterCommand(ev, commandID);
  236. }
  237. #endif
  238.     
  239. #ifdef FW_BUILD_MAC
  240. //----------------------------------------------------------------------------------------
  241. //    FW_CMenuBar::PrivMacGetCommand
  242. //----------------------------------------------------------------------------------------
  243. inline ODCommandID FW_CMenuBar::PrivMacGetCommand(Environment* ev,
  244.                                                 ODMenuID menuID,
  245.                                                 short itemID)
  246. {
  247.     return fODMenuBar->GetCommand(ev, menuID, itemID);
  248. }
  249. #endif
  250.     
  251. //----------------------------------------------------------------------------------------
  252. //    FW_CMenuBar::PrivAddSubMenu
  253. //----------------------------------------------------------------------------------------
  254. inline void FW_CMenuBar::PrivAddSubMenu(Environment* ev,
  255.                                         ODMenuID subMenuID,
  256.                                         ODPlatformMenu platformMenu)
  257. {
  258. #ifdef FW_BUILD_MAC
  259.     fODMenuBar->AddSubMenu(ev, subMenuID, platformMenu, fODPart);
  260. #endif
  261. #ifdef FW_BUILD_WIN
  262.     // [WIN_PORT] AddSubMenu is missing in OpenDoc/Win!
  263. #endif
  264. }
  265.  
  266. //----------------------------------------------------------------------------------------
  267. //    FW_CMenuBar::PrivRemoveMenu
  268. //----------------------------------------------------------------------------------------
  269. inline void FW_CMenuBar::PrivRemoveMenu(Environment* ev, 
  270.                                         ODMenuID menuID)
  271. {
  272.     fODMenuBar->RemoveMenu(ev, menuID);
  273. }
  274.  
  275. #endif
  276.